<template>
    <div class="login-container">
        <el-form :model="form" ref="formRef" class="login-form"  status-icon>
            <el-form-item label="Password" >
                <el-input v-model="form.password" type="password" autocomplete="off" />
            </el-form-item>
            <el-form-item >
                <el-button type="primary" @click="handleLogin">Login</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { invoke } from '@tauri-apps/api/tauri';
// import type { ComponentSize, FormInstance, FormRules } from 'element-plus'

const form = ref({ username: '', password: '' });
const formRef = ref(null);
const router = useRouter();

const handleLogin = () => {
    // Basic validation
    // if (form.value.username && form.value.password) {
    //     router.push('/main');
    // } else {
    //     alert('Please enter username and password');
    // }
    try {
        invoke('login', { passwd: form.value.password}).then((res) => {
            console.log(res);
            if(res) {
                router.push('/main');
            }
        })
    }
    catch (err) {
        console.log(err);
    }
};
</script>

<style>
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 90vh;
}

.login-form {
    width: 300px;
}
</style>